<html>
<head><meta charset="utf-8"><title>-Z dual-proc-macros · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html">-Z dual-proc-macros</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="177107343"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177107343" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177107343">(Oct 01 2019 at 23:20)</a>:</h4>
<p><span class="user-mention" data-user-id="116466">@Zoxc</span> <span class="user-mention" data-user-id="116015">@Alex Crichton</span> <br>
Could you clarify a couple of details regarding that option?</p>



<a name="177107462"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177107462" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177107462">(Oct 01 2019 at 23:22)</a>:</h4>
<hr>
<p>Can the compiler rely on metadata in the host and target versions of the proc macro library being the same?<br>
By metadata I mean things like name, edition, etc. (Everything beside the target, basically.)</p>



<a name="177107688"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177107688" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177107688">(Oct 01 2019 at 23:25)</a>:</h4>
<p>In theory, these two crates are loaded using two independent crate searches and you can place crates with entirely different contents to be found by those searches.<br>
On the other hand that's certainly not an intended use.</p>



<a name="177107929"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177107929" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177107929">(Oct 01 2019 at 23:29)</a>:</h4>
<p>Looks like right now this kind of metadata is almost always used from the target version, except when it isn't (?!), e.g. for the crate edition in <code>fn load_proc_macro</code>.</p>



<a name="177108033"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177108033" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177108033">(Oct 01 2019 at 23:30)</a>:</h4>
<p>I'm not personally familiar with the rustc implementation of this flag, just the cargo part for myself</p>



<a name="177108041"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177108041" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177108041">(Oct 01 2019 at 23:30)</a>:</h4>
<p>Is this a bug? Should the edition be taken from the target version as well?<br>
Otherwise it looks like the host version is used <em>only</em> for <code>dlsym</code>ing.</p>



<a name="177108048"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177108048" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177108048">(Oct 01 2019 at 23:30)</a>:</h4>
<p>But in cargo at least and I believe the expected use is that these are compiled exactly the same way except for target</p>



<a name="177108066"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177108066" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177108066">(Oct 01 2019 at 23:31)</a>:</h4>
<p>Yeah, cargo reflects the intended use.</p>



<a name="177108097"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177108097" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177108097">(Oct 01 2019 at 23:31)</a>:</h4>
<p>I haven't actually reviewed the rustc implementation at all (or I forget it), so I'll defer to zoxc or when I'm next at a computer tomorrow</p>



<a name="177108140"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177108140" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177108140">(Oct 01 2019 at 23:32)</a>:</h4>
<p>They should be the same except for the target, but I did try to only use stuff from the target libraries for everything but executing code</p>



<a name="177108289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177108289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177108289">(Oct 01 2019 at 23:34)</a>:</h4>
<blockquote>
<p>only use stuff from the target libraries for everything but executing code</p>
</blockquote>
<p>This matches the description in <a href="https://github.com/rust-lang/rust/pull/58013#issuecomment-459805962" target="_blank" title="https://github.com/rust-lang/rust/pull/58013#issuecomment-459805962">https://github.com/rust-lang/rust/pull/58013#issuecomment-459805962</a>.<br>
Then the edition bit must be a bug.</p>



<a name="177108325"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177108325" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177108325">(Oct 01 2019 at 23:35)</a>:</h4>
<p>Nice, if it's a bug, then it simplifies things.</p>



<a name="177108649"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177108649" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177108649">(Oct 01 2019 at 23:41)</a>:</h4>
<p>Where is the edition related code?</p>



<a name="177108802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177108802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177108802">(Oct 01 2019 at 23:43)</a>:</h4>
<p><code>fn load_proc_macro</code> in <code>decoder.rs</code>, the edition is taken from the <code>host_lib</code> metadata, while everything else is taken from <code>self.root</code> which is the target metadata.</p>



<a name="177109152"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177109152" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177109152">(Oct 01 2019 at 23:48)</a>:</h4>
<p>It kinda make sense since <code>SyntaxExtension</code> is the thing executing the macros. Not sure what it is used for though. Also different editions between the target and host isn't really a supported use case =P</p>



<a name="177130636"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177130636" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177130636">(Oct 02 2019 at 08:23)</a>:</h4>
<p><span class="user-mention" data-user-id="116466">@Zoxc</span> <br>
One more question: why is <code>-Z dual-proc-macros</code> required only in rustc bootstrap?<br>
The situation "cross compile a library which uses (possibly reexports) a proc macro crate" seems to happen during any cross-compilation?<br>
In this case the host version of the proc macro crate is needed to run code during the build, and the target version is needed to read metadata for reexports etc.</p>



<a name="177130649"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177130649" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177130649">(Oct 02 2019 at 08:23)</a>:</h4>
<p>How is rustc different?</p>



<a name="177130750"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177130750" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177130750">(Oct 02 2019 at 08:25)</a>:</h4>
<p>Also, what happens if we read metadata from the host version? How exactly is it incompatible? (If at least logically the metadata in both host and target versions is supposed to be the same.)</p>



<a name="177131142"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177131142" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177131142">(Oct 02 2019 at 08:32)</a>:</h4>
<p>Also, do the host and target versions have the same <code>CrateDisambiguator</code> or different?<br>
(I'll investigate some of this myself in a couple of days, but leaving questions in the meantime won't hurt, I guess.)</p>



<a name="177140489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177140489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177140489">(Oct 02 2019 at 11:20)</a>:</h4>
<blockquote>
<p>How is rustc different?</p>
</blockquote>
<p>I might be wrong -- and would appreciate <span class="user-mention" data-user-id="116466">@Zoxc</span> confirming -- but I _think_ the difference is that rustc is "unique" in that we have plugins that link against it and want to use the proc macros from its sysroot</p>



<a name="177140498"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177140498" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177140498">(Oct 02 2019 at 11:20)</a>:</h4>
<p>However, if we were to just compile them for the host, then that wouldn't work if the plugin is built for the target</p>



<a name="177140535"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177140535" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177140535">(Oct 02 2019 at 11:21)</a>:</h4>
<p>Though I suspect that might be rather a bug in the compiler (i.e., we should never need to "run" proc macros anywhere but the host) and dual-proc-macros just patch over it</p>



<a name="177174908"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177174908" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177174908">(Oct 02 2019 at 17:51)</a>:</h4>
<p><span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> Normally cargo cross compiles the library only then links that to a proc macro crate for the host. This means that you cannot copy the library over to the target and use it with a Rust compiler running on that target.</p>



<a name="177175849"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177175849" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177175849">(Oct 02 2019 at 18:00)</a>:</h4>
<p>why does the library contain any references to the proc macro?</p>



<a name="177175868"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177175868" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177175868">(Oct 02 2019 at 18:01)</a>:</h4>
<p>I would expect us to compile those out so to speak, i.e., that they only need to be available at build time</p>



<a name="177179134"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177179134" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177179134">(Oct 02 2019 at 18:36)</a>:</h4>
<p>The rlib or dylib metadata will reference the proc macro, and it has to for reexports to work.</p>



<a name="177179774"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177179774" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177179774">(Oct 02 2019 at 18:43)</a>:</h4>
<blockquote>
<p>and use it with a Rust compiler running on that target.</p>
</blockquote>
<p>Aha, this seems to be the key missing piece - there are actually <em>two</em> compilers running on two different targets!<br>
And they both work with a single library.<br>
I'll try to write some pseudo-code below to understand the exact configuration.</p>



<a name="177180078"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177180078" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177180078">(Oct 02 2019 at 18:46)</a>:</h4>
<hr>
<p>There are two libraries <code>PM</code> (proc macro) and <code>L</code> (uses the proc macro and reexports it).<br>
There are two targets <code>T1</code> and <code>T2</code>.</p>



<a name="177180585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177180585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177180585">(Oct 02 2019 at 18:52)</a>:</h4>
<p>When cross-compiling <code>L</code> from <code>T1</code> to <code>T2</code> we have:<br>
- Compiler built for <code>T1</code> and running on it.<br>
- Library <code>PM</code> built for <code>T1</code>.<br>
- Library <code>L</code> built for <code>T2</code>, to run proc macros the compiler-T1 <code>dlsym</code>s code from <code>PM-T1</code>, to reexport proc macros the compiler-T1 reads metadata from <code>PM-T1</code>.</p>



<a name="177181047"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177181047" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177181047">(Oct 02 2019 at 18:56)</a>:</h4>
<p>(That's a normal, non-rustc story.)</p>



<a name="177181546"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177181546" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177181546">(Oct 02 2019 at 19:02)</a>:</h4>
<p>Now rustc story when we have a second compiler.<br>
- The second compiler is built for <code>T2</code> and is running on it.<br>
- We have our previously built library <code>L-T2</code>.<br>
- Using <code>L-T2</code> - to run proc macros reexported by <code>L-T2</code> the compiler-T2 <code>dlsyms</code>s code from <code>PM-T2</code>, to reexport proc macros reexported by <code>L-T2</code> further the compiler-T2 reads metadata from <code>PM-T2</code>.</p>



<a name="177181669"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177181669" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177181669">(Oct 02 2019 at 19:03)</a>:</h4>
<p><span class="user-mention" data-user-id="116466">@Zoxc</span> <br>
Is the description above correct?<br>
If it's correct, then we need to produce <code>PM-T2</code> at some point, and that explains why we need <code>-Z dual-proc-macros</code> for Cargo.</p>



<a name="177181822"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177181822" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177181822">(Oct 02 2019 at 19:05)</a>:</h4>
<p>It doesn't explain why we need <code>-Z dual-proc-macros</code> for <code>rustc</code> though, in both cases we can dlsym and metadata-read the same library with target matching the compiler's one (aka host).</p>



<a name="177184281"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177184281" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177184281">(Oct 02 2019 at 19:35)</a>:</h4>
<p>So am I right in saying that we wouldn't need this if we never re-exported proc macros? i.e., if there was a direct dep on any proc macro crates. That seems like a reasonable ask (to me); basically saying "we don't ship proc macros in sysroot"</p>



<a name="177184367"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177184367" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177184367">(Oct 02 2019 at 19:36)</a>:</h4>
<p>we'd need some sort of autopublish or w/e business if clippy etc want to directly use rustc_macros for example, but I imagine that would be not too difficult.</p>



<a name="177184876"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177184876" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177184876">(Oct 02 2019 at 19:42)</a>:</h4>
<p><span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> Not quite, the <code>L-T2</code> library built the "normal" way directly links to the <code>PM-T1</code> proc macro, so it can't be used with the compiler on <code>T2</code>, since it can't run <code>PM-T1</code>. We need to cross compile <code>L-T2</code> using <code>-Z dual-proc-macros</code>, where cargo builds both <code>PM-T1</code> and <code>PM-T2</code>, rustc loads metadata for both; uses <code>PM-T1</code> to run the macros, but only links the resulting <code>L-T2</code> to <code>PM-T2</code>. Then we have <code>L-T2</code> and <code>PM-T2</code> as if they were built by rustc running on <code>T2</code>.</p>



<a name="177186495"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177186495" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177186495">(Oct 02 2019 at 20:00)</a>:</h4>
<blockquote>
<p>the <code>L-T2</code> library built the "normal" way directly links to the <code>PM-T1</code> proc macro</p>
</blockquote>
<p>Why does it need to <em>link</em> to it?<br>
So far we've been talking only about the compiler <code>dlopen</code>ing/<code>dlsym</code>ing it and reading metadata from it, but not about linking to it.</p>



<a name="177186639"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177186639" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177186639">(Oct 02 2019 at 20:01)</a>:</h4>
<p>When I say link, I mean that the metadata refers to it</p>



<a name="177187811"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177187811" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177187811">(Oct 02 2019 at 20:13)</a>:</h4>
<blockquote>
<p>I mean that the metadata refers to it</p>
</blockquote>
<p>Hmm, is it somehow hardcoded inside <code>L-T2</code> through paths or fingerprints?<br>
I thought <code>L-T2</code> refers to something more flexible like "just something named <code>PM</code>" and while processing <code>L-T2</code> we can find <code>PM-T1</code> through crate search if the compiler is <code>T1</code> and can find <code>PM-T2</code> thorough crate search if the compiler is <code>T2</code>.</p>



<a name="177187983"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177187983" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177187983">(Oct 02 2019 at 20:15)</a>:</h4>
<p><code>L-T2</code> will link to the proc macro with a specific crate disambiguator (and probably target triple too)</p>



<a name="177188034"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177188034" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177188034">(Oct 02 2019 at 20:15)</a>:</h4>
<p>We can have multiple versions of a proc macro in the search path (though <code>-Z dual-proc-macros</code> doesn't support that)</p>



<a name="177188179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177188179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177188179">(Oct 02 2019 at 20:17)</a>:</h4>
<p>Since if there's multiple proc macro crates for the host, it won't know which ones corresponds to the proc macro crate for the target</p>



<a name="177188879"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177188879" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177188879">(Oct 02 2019 at 20:24)</a>:</h4>
<p>Ok, I think I understand it now.<br>
What a mess -_-</p>



<a name="177189192"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177189192" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177189192">(Oct 02 2019 at 20:28)</a>:</h4>
<p>I think it would be interesting to find a way to refer to "flexible <code>PM</code>" from <code>L-T2</code> instead of hardcoding, so it could resolve to different crates (<code>PM-T1</code> or <code>PM-T2</code>) when <code>L-T2</code> is processed by different compilers (<code>T1</code> or <code>T2</code> respectively).<br>
(In that case we wouldn't need <code>-Z dual-proc-macros</code> at least on the <code>rustc</code> side.)</p>



<a name="177190684"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177190684" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177190684">(Oct 02 2019 at 20:43)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> </p>
<blockquote>
<p>So am I right in saying that we wouldn't need this if we never re-exported proc macros?</p>
</blockquote>
<p>Looks like that, except the compiler should known about it somehow (e.g. we can use <code>rustc_macros</code> only through <code>#[no_link] extern crate rustc_macros</code> or something).</p>



<a name="177190769"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177190769" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177190769">(Oct 02 2019 at 20:44)</a>:</h4>
<p>hm, I guess we have e.g. <code>serde = { version = "1", features = ["derive"] }</code> though in deps which might make this not possible</p>



<a name="177190822"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177190822" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177190822">(Oct 02 2019 at 20:45)</a>:</h4>
<p>IIRC we have a special mode in rustc_metadata for "just macro uses" which maybe isn't fully applicable to proc macros, but might be relevant here?</p>



<a name="177190829"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177190829" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177190829">(Oct 02 2019 at 20:45)</a>:</h4>
<p>Ah, of course, <code>rustc_macros</code> is not the only proc macro thing we need.</p>



<a name="177190941"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177190941" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177190941">(Oct 02 2019 at 20:46)</a>:</h4>
<p>though -- I might be wrong here -- but is it true that regular crates build just fine? e.g. if clippy et al used rustc_macros by path and rebuilt it then we'd work just fine</p>



<a name="177190952"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177190952" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177190952">(Oct 02 2019 at 20:46)</a>:</h4>
<p>(and same with serde, etc.)</p>



<a name="177190977"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177190977" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177190977">(Oct 02 2019 at 20:46)</a>:</h4>
<blockquote>
<p>IIRC we have a special mode in rustc_metadata for "just macro uses"</p>
</blockquote>
<p>Yes, that's exactly what I've been talking about - <code>DepKind::UnexportedMacrosOnly</code>, which is currently expressible only as <code>#[no_link] extern crate</code> in the language.</p>



<a name="177190991"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177190991" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177190991">(Oct 02 2019 at 20:46)</a>:</h4>
<p>ah okay</p>



<a name="177191006"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177191006" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177191006">(Oct 02 2019 at 20:46)</a>:</h4>
<p>that is, the problem only arises if you re-export a proc macro from a precompiled dependency (i.e., in the sysroot)</p>



<a name="177191023"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177191023" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177191023">(Oct 02 2019 at 20:47)</a>:</h4>
<p>if you re-export a proc macro normally then things work fine</p>



<a name="177191313"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/-Z%20dual-proc-macros/near/177191313" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/-Z.20dual-proc-macros.html#177191313">(Oct 02 2019 at 20:50)</a>:</h4>
<p>Using webassembly for proc macros would also avoid this =P</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>